package com.qdlc.p2p.biz.service.impl;

import org.springframework.stereotype.Service;

import com.qd.p2p.sina.pay.enums.IdentityType;
import com.qdlc.p2p.biz.service.AbstractCollectService;
import com.qdlc.p2p.common.constant.NotifyUrl;
import com.qdlc.p2p.common.constant.SinaConstant;
import com.qdlc.p2p.common.constant.Summary;
import com.qdlc.p2p.common.constant.TradeCode;
import com.qdlc.p2p.common.util.OrderNoUtils;
import com.qdlc.p2p.dal.common.SystemConfigHelper;
import com.qdlc.p2p.dal.common.SystemConfigHelper.Nid;
import com.qdlc.p2p.dal.dto.TppTradeLog;
import com.qdlc.p2p.dal.dto.User;

/**
 * 提现手续费-代收服务类
 * @author linya
 */
@Service
public class CashFeeCollectServiceImpl extends AbstractCollectService{

	private final static String BUSINESS_NAME = "提现手续费-代收-";
	
	// 提现用户
	private final static ThreadLocal<User> accountCashUser = new ThreadLocal<User>();
	
	// 提现金额
	private final static ThreadLocal<Double> webCashFee = new ThreadLocal<Double>();
	
	@Override
	public String getCallBackUrl() {
		return WEB_URL.concat(NotifyUrl.CASH_FEE_NOTIFY_COLLECT_URL).concat(".html");
	}

	@Override
	public String getBusinessName() {
		return BUSINESS_NAME;
	}

	@Override
	public TppTradeLog getTppTradeLog() {
		TppTradeLog tppTradeLog = new TppTradeLog();
		User user = accountCashUser.get();
		tppTradeLog.setTppUserCustId(user.getTppUserCustId());
		tppTradeLog.setToTppUserCustId(SystemConfigHelper.getValue(Nid.MEMBER_EMAIL));
		tppTradeLog.setIdentityType(IdentityType.UID.name());
		tppTradeLog.setMoney(webCashFee.get());
		tppTradeLog.setOrderNo(OrderNoUtils.getSerialNumber());
		tppTradeLog.setSinaStatus(SinaConstant.TRADE_STATUS_WAIT_PAY);
		tppTradeLog.setTradeType(TradeCode.C1008.toString());
		tppTradeLog.setServiceType(Summary.CASH_FEE.getSummaryType());
		tppTradeLog.setMemo(Summary.CASH_FEE.getSummaryName());
		return tppTradeLog;
	}

	@Override
	public void analyzePars(Object... pars) {
		if (pars.length != 2) {
            throw new IllegalArgumentException("参数个数不正确!");
        }
		try {
			accountCashUser.set((User) pars[0]);
			webCashFee.set((Double)pars[1]);
		} catch (Exception e) {
			throw new IllegalArgumentException("参数类型不正确!");
		}
	}

	@Override
	public void tradeFinish(TppTradeLog tppTradeLog, String depositStatus, double tradeAmount) {
		super.tradeFinishForStatus(tppTradeLog, depositStatus, tradeAmount);
	}

	@Override
	public void tradeSuccess(TppTradeLog tppTradeLog, String depositStatus) {
		super.tradeSuccessForStatus(tppTradeLog, depositStatus);
	}

	@Override
	public void tradeFail(TppTradeLog tppTradeLog, String depositStatus) {
		super.tradeFailForStatus(tppTradeLog, depositStatus);
	}

}
